﻿using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading.Tasks;

namespace Ordering.API.Application.Commands
{
    /// <summary>
    /// 创建订单命令
    /// </summary>
    [DataContract]
    public class CreateOrderCommand
        : IRequest<bool>
    {
        [DataMember]
        private readonly List<OrderItemDTO> _orderItems;

        [DataMember]
        public IEnumerable<OrderItemDTO> OrderItems => _orderItems;

        [DataMember]
        private readonly AddressDTO _address;

        [DataMember]
        public AddressDTO Address => _address;

        [DataMember]
        public string CustomerCode { get; private set; }
        /// <summary>
        /// 预约时间
        /// </summary>
        [DataMember]
        public DateTime AppointmentTime { get; private set; }
        /// <summary>
        /// 订单类别(0:仍垃圾 1：取快递)
        /// </summary>
        [DataMember]
        public int OrderType { get; private set; }
        /// <summary>
        /// 描述
        /// </summary>
        [DataMember]
        public string Description { get;private set; }
        /// <summary>
        /// 备注
        /// </summary>
        [DataMember]
        public string Remark { get; private set; }


        public CreateOrderCommand(string customerCode,DateTime appointmentTime,int orderType,string description,string remark,List<OrderItemDTO> orderItems,AddressDTO address)
        {
            this.CustomerCode = customerCode;
            this.AppointmentTime = appointmentTime;
            this.OrderType = orderType;
            this.Description = description;
            this.Remark = remark;
            _orderItems = orderItems;
            _address = address;
        }
    }
    /// <summary>
    /// 订单明细
    /// </summary>
    public class OrderItemDTO
    {
        public string ProductCode { get; set; }
        /// <summary>
        /// 单价
        /// </summary>
        public decimal ProductPrice { get; set; }
        /// <summary>
        /// 产品名称
        /// </summary>
        public string ProductName { get; set; }
        /// <summary>
        /// 数量
        /// </summary>
        public int Num { get; set; }
        /// <summary>
        /// 取件码
        /// </summary>
        public string ExpressCode { get; set; }
        /// <summary>
        /// 备注
        /// </summary>
        public string Remarks { get; set; }
    }
    /// <summary>
    /// 地址
    /// </summary>
    public class AddressDTO
    {
        /// <summary>
        /// 省
        /// </summary>
        public String Province { get; private set; }
        /// <summary>
        /// 市
        /// </summary>
        public String City { get; private set; }
        /// <summary>
        /// 区
        /// </summary>
        public String Area { get; private set; }

        public string Town { get; private set; }
        /// <summary>
        /// 详细地址
        /// </summary>
        public string DetailedAddress { get; private set; }

        /// <summary>
        /// 扩展字段（订单为取快递类型则为：快递店地址）
        /// </summary>
        public string ExtendField { get; private set; }
        /// <summary>
        /// 经度
        /// </summary>
        public decimal? Latitude { get; set; }
        /// <summary>
        /// 纬度
        /// </summary>
        public decimal? Longitude { get; set; }

        public AddressDTO(string province,string city,string area, string town,string detailedAddress,decimal? latitude, decimal? longitude,string extendField)
        {
            this.Province = province;
            this.City = city;
            this.Area = area;
            this.Town = town;
            this.DetailedAddress = detailedAddress;
            this.Latitude = latitude;
            this.Longitude = longitude;
            this.ExtendField = extendField;
        }
    }
}
